<template>
  <div>
    <BasicTable @register="registerTable">
      <template #action="{ record }">
        <TableAction
          :actions="[
            {
              icon: 'ant-design:search-outlined',
              tooltip: '查看日志详情',
              onClick: handleView.bind(null, record),
            },
          ]"
        />
      </template>
    </BasicTable>
    <OptLogDrawer @register="registerDrawer" @success="reload" />
  </div>
</template>
<script lang="ts">
  import { defineComponent } from 'vue';

  import { BasicTable, useTable, TableAction } from '/@/components/Table';

  import { useDrawer } from '/@/components/Drawer';
  import OptLogDrawer from './OptLogDrawer.vue';

  import { columns, searchFormSchema } from './log.data';
  import { pageList } from './log.api';

  export default defineComponent({
    name: 'OptLogManagement',
    components: { BasicTable, TableAction, OptLogDrawer },
    setup() {
      const [registerDrawer, { openDrawer }] = useDrawer();
      const [registerTable, { reload }] = useTable({
        title: '操作日志列表',
        api: pageList,
        columns,
        formConfig: {
          labelWidth: 120,
          schemas: searchFormSchema,
        },
        useSearchForm: true,
        showTableSetting: true,
        bordered: true,
        showIndexColumn: false,
        actionColumn: {
          width: 80,
          title: '操作',
          dataIndex: 'action',
          slots: { customRender: 'action' },
          fixed: undefined,
        },
      });

      function handleView(record: Recordable) {
        openDrawer(true, { record });
      }

      return {
        registerDrawer,
        registerTable,
        reload,
        handleView,
      };
    },
  });
</script>
